package com.company;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
//        String var1 = "035.8C^000037.8C^000037.8C2";
//        //var1 = "^0000";
//        String s = "";
//        String regEx="\\^(.*?)C";
//        Pattern p = Pattern.compile(regEx);
//        Matcher m = p.matcher( var1 );
//
//        int matcher_start = 0;
//        while (m.find(matcher_start)){
//            System.out.println("count="+m.groupCount());
//            System.out.println(m.group(0));
//            System.out.println(m.group(1));
//            matcher_start = m.end();
//        }
//        s = m.replaceAll("");
//        System.out.println( s+"====" );

//        int aa = 200;
//        byte a = (byte)aa;
//        System.out.println( a+"====" );
//        int b=0xff&a; //正确
//        System.out.println( b+"====" );

       // byte[] datas = new byte[]{(byte)0x33,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0xA0,(byte)0x1E,(byte)0x01,(byte)0x00};
       // byte[] datas = new byte[]{(byte)0x43,(byte)0x00,(byte)0x00,(byte)0x00,
        //        (byte)0x00,(byte)0x02,(byte)0x23,(byte)0x1E,(byte)0x02,(byte)0x1A,(byte)0x01,(byte)0xC4};
        byte[] datas = new byte[12];
        datas[0] = (byte)0xaa;
        datas[1] = (byte)0x0a;
        datas[2] = (byte)0x33;
        datas[3] = (byte)0x00;
        datas[4] = (byte)0x00;
        datas[5] = (byte)0x00;
        datas[6] = (byte)0x00;
        datas[7] = (byte)170;
        datas[8] = (byte)30;
        datas[9] = (byte)0x01;
        datas[10] = (byte) 0x00 ;
        //datas[11] = DataAnalysis.fatChecksum( datas );
        byte bb = fatChecksum( datas );
        int cc = 0xff&bb;
        System.out.println( cc );
        //170 13 67 00 00 00 00 00 158 25 01 21 03 42 61
        //170 13 67 00000000 00 148 25 01 21 03 36 45
        byte[] aa = {(byte)0x00,(byte)0x94};
        System.out.println( (0x00 * 0x100 + 0x9e) & 0xffff );
        System.out.println(  ( 0xffff & ( 0xff&aa[0] * 0x100 + 0xff&aa[1] ) )*0.1 );
        DecimalFormat df = new DecimalFormat("##0.0");
        double height2 = 170 * 170;
        df.setRoundingMode(RoundingMode.DOWN);
        String bmi = df.format(16.3 / height2);  //5.6
        System.out.println( 16.3 / height2 * 10000 );


        System.out.println( 170 / 100 );

        System.out.println( 170 * 170 * 0.01*0.01 );
        System.out.println( 170 * 170 * 0.0001 );

        HashMap<String,String> aaa = new HashMap<>();

        HashMap<String,String> bbb = new HashMap<>();
        bbb.put( "1","1" );
        bbb.put( "3","3" );
        HashMap<String,String> ccc = new HashMap<>();
        ccc.put( "1","6" );
        ccc.put( "2","2" );

        aaa.putAll( bbb );
        aaa.putAll( ccc );


        aaa.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String s, String s2) {
                System.out.println( s+"=="+s2 );
            }
        });
        String data = "03451PM00";
        double dl = Double.parseDouble( data.substring( 0, 5 ) );
        System.out.println(  dl );
        System.out.println(  data.substring( 6,7 ).toUpperCase() );

        System.out.println("1,22".split(",").length);
        String[] akk = {"BMI","2"};

        System.out.println( Arrays.binarySearch(akk, "BMI") );

    }
    //体脂称校验和
    public static byte fatChecksum( byte[] datas ){
        byte sum = 0;
        for (byte data : datas) {
            sum += ( (byte)0xff )&data;
        }
        return sum;
    }

}
